package com.example.demo.controller;

import com.example.demo.service.LogService;
import com.example.demo.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RequestMapping("/user2")
@RestController
public class UserController2 {

    @Autowired
    private UserService userService;

    @Autowired
    private LogService logService;

    @Transactional
    @RequestMapping("/registryUser")
    public String registryUser(String userName, String password) {
        // 插入用户表
        Integer re = userService.insertUser(userName, password);
        // 插入日志表
        logService.insertLog(userName, "用户注册");
        log.info("用户注册成功，影响行数：" + re);
        return "用户注册成功";
    }
}
